// components/RefundIdxItem/RefundIdxItem.js
Component({
  properties: {
    cardInfo:{
      type:Object
    }
  },
  data: {
    status:null,
    cardNumLast4:''
  },
  attached: function() {
    let tmp = this.transStatus(this.properties.cardInfo.state)
    let tmp1 = this.properties.cardInfo.bc_bank_number.substring(this.properties.cardInfo.bc_bank_number.length - 4)
    this.setData({
      status: tmp,
      cardNumLast4:tmp1
    })
  },
  methods: {
    toResetCardInfo: function () {
      let that = this
      wx.navigateTo({
        url: "/pages/creditCardReset/index",
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', { cardInfo: that.properties.cardInfo })
        }
      })
    },
    toSeeRecord: function () {
      let that = this
      wx.navigateTo({
        url: `/pages/refundRecord/index`,
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', { cardInfo: that.properties.cardInfo })
        }
      })
    },
    toDeal: function () {
      let that = this
      if ([1, 2, 5].includes(this.properties.cardInfo.state)) {
        console.log("去see")
        // wx.navigateTo({
        //   url: "/pages/refundRecord/index"
        // })
      } else {
        console.log("去create")
        wx.navigateTo({
          url: "/pages/refundCreate/index",
          success: function (res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('acceptDataFromOpenerPage', { cardInfo: that.properties.cardInfo })
          }
        })
      }
    },
    toDelCard:function() {
      wx.navigateTo({
        url: "/pages/creditCardDelete/index",
        success: (res) => {
          res.eventChannel.emit('acceptDataFromOpenerPage', { cardInfo: this.properties.cardInfo })
        }
      })
    },
    transStatus: function (state) {
      const result = {
        "-1": { text: "无还款计划", color: "#999999", btnText: "我要还款" },
        "0": { text: "计划未确认", color: "#CC0E4D", btnText: "查看计划" },
        "1": { text: "计划待执行", color: "#0E44CC", btnText: "查看计划" },
        "2": { text: "计划执行中", color: "#08D608", btnText: "查看计划" },
        "3": { text: "计划已完成", color: "#08D608", btnText: "我要还款" },
        "4": { text: "无还款计划", color: "#999999", btnText: "我要还款" },
        "5": { text: "计划已暂停", color: "#CC290E", btnText: "查看计划" },
      }

      return result[`${state}`]
    }
  }
})
